package com.tanhua.admin.service;

import com.tanhua.dubbo.api.MovementApi;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Movement;
import com.tanhua.model.vo.MovementAdminVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/11 19:13
 */
@Service
public class MovementService {

    @DubboReference
    private MovementApi movementApi;

    @DubboReference
    private UserInfoApi userInfoApi;

    /**
     * 动态详情
     *
     * @param id
     * @return
     */
    public MovementAdminVo findByPid(String id) {

        Movement movement = movementApi.findById(id);

        UserInfo userInfo = new UserInfo();
        if (movement != null) {
            Long userId = movement.getUserId();

            userInfo = userInfoApi.findById(userId);
        }
        MovementAdminVo vo = MovementAdminVo.init(userInfo, movement);


        return vo;
    }

    public String pass(String[] item) {


        for (String pid : item) {
            boolean passMovement = movementApi.passMovement(pid, 1);
            if (!passMovement){
                return "审核失败";
            }
        }


        return "审核通过";

    }

    public String reject(String[] item) {

        for (String pid : item) {
            boolean passMovement = movementApi.reject(pid, 2);
            if (!passMovement){
                return "拒绝失败";
            }
        }


        return "拒绝成功";

    }
}
